<template>
  <div>
    <!-- 编辑 -->
    <!-- :visible="true"  -->
    <el-dialog title="编辑相册" 
    :visible.sync="dialogVisible" 
    :before-close="handleClose">
      <div class="createpic">
    <div class="main">
      <el-form label-width="80px" :model="List">
        <el-form-item label="相册编号:">
          <el-input v-model="List.id"></el-input>
        </el-form-item>
        <el-form-item label="相册名称:">
          <el-input v-model="List.name"></el-input>
        </el-form-item>
        <el-form-item label="相册描述:">
          <el-input type="textarea" v-model="List.description"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
       
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sureEditMenu">确 定</el-button>
      </span> 
    </div>
  </div>
    </el-dialog>
  </div>
</template>
<script>
import {EditAlbum} from '@/api/assetsdata'
export default {
  data() {
    return {
      // 控制组件是否显示弹框
      dialogVisible: this.visible,
      // 被修改的菜单，传入的parent(选择的第一个菜单)

      // visible: false,
      List:{}
    };
  },
  props:{
    // 控制是否显示弹框
    visible: { type: Boolean, default: false },
    // 父菜单信息
    parent: {
      type: Object,
      default() {
        return {  };
      },
    },
    id: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  methods:{
    sureEditMenu() {
      // 发送请求前，更新父id
      EditAlbum(this.List.id,this.List).then((res) => {
        if (res.data.code === 0) {
          // 弹框提示成功
          this.$message({
            type: "success",
            message: "编辑成功",
          });
        }
        // 通知父组件添加成功
        this.$emit("editSuccess", true);
        location.reload()
        // this.$parent.getMenu()//不推荐
        // 关闭当前组件
        this.dialogVisible = false;
      });
    },
    handleClose(done) {
      // 告诉父组件更新visible 值false
      // 关闭弹框
      done();
    },
    // cancle(){
    //   this.$emit('close',false)
    // },
    // editAlbum(){
    //   EditAlbum(this.id).then((res) => {
    //     if (res.data.code === 0) {
    //       this.$message({
    //         type: "success",
    //         message: "编辑成功，2秒后自动返回",
    //       });
    //       setTimeout(() => {
    //         this.$router.back();
    //       }, 1500);
    //     }
    //     this.$emit('close',false)  
       
    //   });
    
    // }
  },
  watch: {
    dialogVisible: {
      handler() {
        // 监听dialogVisible变化，告诉父组件更新visible属性值
        this.$emit("update:visible", this.dialogVisible);
      },
      deep: true,
    },
    visible: {
      handler() {
        // 当复制的visible发生变化时候更新当前组件的
        this.dialogVisible = this.visible;
      },
    },
    parent: {
      handler() {
        // 当复制的visible发生变化时候更新当前组件的
        this.item = { ...this.parent };
      },
      deep: true,
    },
    id: {
      handler() {
        this.List = {...this.id};
      },
      deep:true
    },
  },
 
};
</script>

